<div class="layui-fluid layui-anim febs-anim-up" id="febs-index" lay-title="评分页">
    <div class="layui-row layui-col-space8 febs-container">
        <div class="layui-col-md12 layui-col-sm12 layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-body layui-anim layui-anim-fadein">
                    <div class="layui-row welcome-info">
                        <div class="layui-col-md6 layui-col-sm12 layui-col-xs12">
                            <div class="layui-row welcome-info-wrapper">
                                <div class="user-header">
                                    </i><a href="javascript:history.go(-1);"><h3>返回上一页</h3></a>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-md6 layui-col-sm12 layui-col-xs12">
                            <div class="layui-col-md-offset5">
                                <table class="login-count-table" id="table_case">
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md6 layui-col-sm6 layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form" lay-filter="example" method="post">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;font-size: small">
                            <legend style="font-size: medium;font-weight: bold">提案详情:</legend>
                        </fieldset>
                        <label class="layui-form-label">提案编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="ppsNo" readonly="true" class="layui-input"
                                   style="background-color: rgb(232,232,232)">
                        </div>
                        <br>
                        <div>
                            <label class="layui-form-label">提案日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="ppsDate" readonly="true" class="layui-input"
                                       style="background-color: rgb(232,232,232)">
                            </div>
                        </div>
                        <br>
                        <div>
                            <label class="layui-form-label">提案名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="ppsName" lay-verify="notNull" class="layui-input">
                            </div>
                        </div>
                        <br>
                        <div>
                            <label class="layui-form-label">提案事由</label>
                            <div class="layui-input-block">
                            <textarea type="text" name="reasonDesc" class="layui-textarea required" required="true"
                                      lay-verify="notNull" placeholder="简要说明提案拟改进的具体事项"/>
                            </div>
                        </div>
                        <br>
                        <div>
                            <label class="layui-form-label">现状缺点</label>
                            <div class="layui-input-block">
                                <textarea type="text" name="defectDesc" class="layui-textarea" required="true"
                                          lay-verify="notNull" placeholder="详细说明在提案未提出前, 原有情形之未尽妥善之处以及改进意见"/>
                            </div>
                        </div>
                        <br>
                        <label class="layui-form-label">改进意见</label>
                        <div class="layui-input-block">
                            <textarea type="text" name="proposeDesc" class="layui-textarea" required="true"
                                      lay-verify="notNull" placeholder="详细说明提案改善的具体办法,包括方法,程序及步骤, 以及估计投资额,投资回收期等, 可另附具体材料"/>
                        </div>
                        <br>
                        <label class="layui-form-label">预期效果</label>
                        <div class="layui-input-block">
                            <textarea type="text" name="resulrDesc" class="layui-textarea" required="true"
                                      lay-verify="notNull"  placeholder="详细说明提案采纳后可能获得的成效, 包括提案效率, 简化作业, 增加销售, 创造利润或节省开支等"/>
                        </div>
                        <br>
                        <hr>
                        <input name="orgId" id="orgId" type="hidden">
                        <br>
                        <div align="center" style="" id="subm">
                            <button class="layui-btn layui-btn-normal layui-border-blue" lay-submit
                                    lay-filter="subm1">保存
                            </button>
                            <button class="layui-btn layui-btn-normal layui-border-blue" lay-submit
                                    lay-filter="subm2">提交提案
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" th:inline="javascript">
    layui.use(['febs', 'rate', 'form', 'jquery', 'layer', 'table'], function () {
        let $ = layui.$ //重点处
            , rate = layui.rate
            , form = layui.form
            , layer = layui.layer
            , table = layui.table
            , url = window.location.href
            , febs = layui.febs
            , ppsNo = getQueryVariable("ppsNo");

        function getData() {
            if (ppsNo) {
                $.ajax({
                    url: "/sys/proposal/get/" + ppsNo,
                    method: 'get',
                    dataType: 'text',
                    contentType: 'application/json',
                    timeout: 5000,
                    success: function (res) {
                        var result = JSON.parse(res)
                        if (result.code == 200) {
                            var data = result.data;
                            //表单赋值
                            $(function () {
                                form.val('example', {
                                    "ppsNo": data.ppsNo
                                    , "ppsName": data.ppsName
                                    , "ppsDate": data.ppsDate
                                    , "reasonDesc": data.reasonDesc
                                    , "defectDesc": data.defectDesc
                                    , "proposeDesc": data.proposeDesc
                                    , "resulrDesc": data.resulrDesc
                                    , "deptname": data.deptname
                                });
                            });
                        }
                    },
                    error: function (data) {
                        alert(data)
                    }
                });
            } else {
                $(function () {
                    form.val('example', {
                        "ppsNo": ''
                        , "ppsName": ''
                        , "ppsDate": ''
                        , "reasonDesc": ''
                        , "defectDesc": ''
                        , "proposeDesc": ''
                        , "resulrDesc": ''
                        , "deptname": ''
                    });
                });
            }
        }

        getData();
        if (!getQueryVariable()) {
            document.body.eventBus.addEvent('refreshProposalEdit', function() {
                getData()
            })
        } else {
            document.body.eventBus.addEvent('refreshProposalEdit' + ppsNo, function() {
                getData()
            })
        }

        //监听表格点击事件,点击行
        form.on('submit(subm1)', function (data) {
            data.field.status = 1;
            data.field.ppsNo = ppsNo;
            $.ajax({
                url: "sys/proposal/save",
                method: 'post',
                data: JSON.stringify(data.field),
                dataType: 'text',
                contentType: 'application/json',
                timeout: 5000,
                success: function (res) {
                    let result = JSON.parse(res)
                    if (result.code == 200) {
                        layer.msg(result.message)
                    } else
                        layer.msg(result.message)
                },
                error: function (data) {
                    alert(JSON.stringify(data))
                }
            });
            setTimeout(function () {
                document.body.eventBus.removeEvent('refreshProposalEdit')
                document.body.eventBus.fireEvent('refreshProposalList')
                window.location.href = url.substring(0, url.lastIndexOf("/"));
            }, 2000);//两秒后返回评价列表页面
            return false;
        });
        form.on('submit(subm2)', function (data) {
            data.field.status = 2;
            data.field.ppsNo = ppsNo;
            $.ajax({
                url: "sys/proposal/save",
                method: 'post',
                data: JSON.stringify(data.field),
                dataType: 'text',
                contentType: 'application/json',
                timeout: 5000,
                success: function (res) {
                    let result = JSON.parse(res)
                    if (result.code == 200) {
                        layer.msg(result.message)
                    } else
                        layer.msg(result.message)
                },
                error: function (data) {
                    alert(JSON.stringify(data))
                }
            });
            setTimeout(function () {
                document.body.eventBus.removeEvent('refreshProposalEdit')
                document.body.eventBus.fireEvent('refreshProposalList')
                window.location.href = url.substring(0, url.lastIndexOf("/"));
            }, 2000);//两秒后返回评价列表页面
            return false;
        });


        function getQueryVariable(variable) {
            return (window.location.toString().split("=")[1]);
        }

        form.verify({
            notNull: function(value, item){
                if(!value){
                    return "请填写此字段"
                }
            }
            });

    });
</script>